package org.jeecg.modules.fw.mapper;

import java.util.HashMap;
import java.util.List;

import cn.hutool.core.date.DateTime;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.fw.entity.FwRoomClean;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: fw_room_clean
 * @Author: jeecg-boot
 * @Date:   2023-04-17
 * @Version: V1.0
 */
public interface FwRoomCleanMapper extends BaseMapper<FwRoomClean> {

    /**
     * 房间消耗品汇总统计
     * @param type
     * @param hotelId
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("<script>select max(c.good_name) as good_name,sum(uc.num) as num,max(c.unit) as unit from  fw_room_clean_use_consumable  uc inner join fw_room_consumable c\n" +
            "on c.id=uc.room_consumable_id\n" +
            "inner join fw_room_clean cl on cl.id=uc.room_clean_id\n" +
            "where c.hotel_id=#{hotelId} and c.type=#{type} and uc.num>0 \n" +
            "<if test='startTime != null'> and cl.create_time &gt;= #{startTime} </if>" +
            "<if test='endTime != null'> and cl.create_time &lt;= #{endTime} </if>" +
            "group by uc.room_consumable_id</script>")
    public List<HashMap<String, Object>> roomUseConsumableSummary(@Param("type") Integer type, @Param("hotelId") String hotelId, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);

    /**
     * 放扫记录汇总
     * @param hotelId
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("<script>select max(w.name) as waiter_name,sum(case cl.room_state when 1 then 1 else 0 end) as tf_num,sum(case cl.room_state when 2 then 1 else 0 end) as xf_num,\n" +
            "0 as zd_num,0 as tc_num,count(0) as count,0 as tc_money\n" +
            "from fw_room_clean cl\n" +
            "inner join bus_waiter_info w on w.id=cl.waiter_id\n" +
            "where cl.hotel_id=#{hotelId} and cl.verify_state=1\n" +
            "<if test='startTime != null'> and cl.create_time &gt;= #{startTime} </if>" +
            "<if test='endTime != null'> and cl.create_time &lt;= #{endTime} </if>" +
            "group by cl.waiter_id</script>")
    public List<HashMap<String, Object>> roomCleanSummary(@Param("hotelId") String hotelId, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);

    @Select("")
    List<FwRoomClean> needCleanRoom(String hotelId);
}
